package com.hadoopSpark.application.test;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.aliyun.configuration.ConfigurationTool;
import com.certificate.tool.SetTrustStore;
import com.common.constant.Constant;

/*
 * 测试，开启一个停止的hadoop应用，不是创建哦
 */
public class StartHadoopApp {
	
	public static void main(String[] args) {
		
		 //get certificate address
		 try {
			 SSLConnectionSocketFactory sslsf = SetTrustStore.getSSLConnection();
			 //httpclient链接
			 CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
			 
			 HttpPost httpPost = new HttpPost(ConfigurationTool.getProperties(Constant.ALIYUN_PROJECTS_URL)+"hadoop7/start");
			 
//			 HttpRequest httpRequest = new HttpRequest(ConfigurationTool.getProperties(Constant.ALIYUN_URL)+"hadoop7/stop");
			 

			 //使用客户端向服务器发送数据
			 HttpResponse httpResponse = httpClient.execute(httpPost);
			 
			 if (httpResponse.getStatusLine().getStatusCode() == 200) {
				HttpEntity resultEntity = httpResponse.getEntity();
				
				//返回结果是，服务器上，返回来的是json字符串数据
				String strResultEntity = EntityUtils.toString(resultEntity);
				System.out.println(strResultEntity);
				System.out.println("SB--------------------> OK");
			} else {
				System.out.println(httpResponse.getStatusLine().getStatusCode());
				System.out.println("SB--------------------> 错啦");
			}
		
			} catch (Exception e) {
				e.printStackTrace();
			}
	}
}
		
		
		
		
		
		
		
		
	
	
	
	
	
